library GameData initializer init requires InitFunction
    globals
        // 玩家数量(表示4个玩家)
        constant integer PLAYER_NUMBER = 3
        // 攻家怪的玩家Id
        constant integer PID_GAME_MONSTER = 6
        // 友军ID
        constant integer PID_GAME_FRIEND = 4
        // 每秒60帧，每帧需要的时间
        constant real FRAME_TIME = 1.0 / 60.0
        // 游戏使用的一些临时存储hash
        hashtable gameht = InitHashtable()

        // 怪物系统伤害系数
        real damaCoefficient = 0.06

        // 是否显示特效(默认1表示显示)
        integer array tx_show_status
        // 玩家传送特效
        string array player_tx_cs

        // 玩家选择的塔
        unit array player_select_ta

    endglobals

    // 获取地图中心矩形
    function getMapCenterRect takes nothing returns rect
        return gg_rct______________000
    endfunction

    // 获取指定玩家的怪物创建区域(目前暂时不用，就是四个边缘区域)
    function getMonsterCreateRect takes integer uid returns rect
        if uid == 0 then
            return gg_rct______________001
        elseif uid == 1 then
            return gg_rct______________002
        elseif uid == 2 then
            return gg_rct______________003
        elseif uid == 3 then
            return gg_rct______________004
        endif
        return null
    endfunction

    // 获取怪物中心创建区域
    function getMonsterCenterRect takes nothing returns rect
        return gg_rct______________009
    endfunction

    // 获取玩家初始点矩形
    function getPlayerStartRect takes integer uid returns rect
        if uid == 0 then
            return gg_rct______________005
        elseif uid == 1 then
            return gg_rct______________006
        elseif uid == 2 then
            return gg_rct______________007
        elseif uid == 3 then
            return gg_rct______________008
        endif
        return null
    endfunction

    // 初始化定义的全局变量
    private function initData takes nothing returns nothing
        local integer uid = 0
        loop
            exitwhen uid > PLAYER_NUMBER
            // 初始化传送特效
            set player_tx_cs[uid] = "Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl"
            set tx_show_status[uid] = 1

            set uid = uid + 1
        endloop
    endfunction


    // 创建基地
    private function createJidi takes nothing returns nothing
        
        local unit u
        local real x = GetRectCenterX(getMapCenterRect())
        local real y = GetRectCenterY(getMapCenterRect())

        // 创建基地
        set u = CreateUnit(Player(PID_GAME_FRIEND), 'H000', x, y, 270.0)

    endfunction

    // 创建指定玩家的防御塔
    function createDefend takes integer pid returns unit
        local unit u
        local real x = GetRectCenterX(getMapCenterRect())
        local real y = GetRectCenterY(getMapCenterRect())

        if pid == 0 then
            set y =  y + 400.0
        elseif pid == 1 then
            set x =  x - 400.0
        elseif pid == 2 then
            set y =  y - 400.0
        elseif pid == 3 then
            set x =  x + 400.0
        endif

        // set u = CreateUnit(Player(pid), 'h000', x, y, 270.0)

        return null
    endfunction

    private function init takes nothing returns nothing
        call initData()

        // 创建基地
        // call createJidi()

        // set player_select_ta[0] = createDefend(0)
    endfunction

endlibrary


